package com.eduhzy.ttw.teacher.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.ObjectUtils;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.core.RouterHub;
import com.eduhzy.ttw.commonsdk.entity.NoticeDetailData;
import com.eduhzy.ttw.commonsdk.entity.PlatformNoticeData;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.di.component.DaggerNoticeDetailComponent;
import com.eduhzy.ttw.teacher.di.module.NoticeDetailModule;
import com.eduhzy.ttw.teacher.mvp.contract.NoticeDetailContract;
import com.eduhzy.ttw.teacher.mvp.presenter.NoticeDetailPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.QMUIEmptyView;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * @author xubo
 * @date 2018-10-12 16:56:47
 */
@Route(path = RouterHub.APP_NOTICEDETAILACTIVITY)
public class NoticeDetailActivity extends BaseActivity<NoticeDetailPresenter> implements NoticeDetailContract.View {
    @Autowired(name = Constants.PARCELABLE_DATA)
    PlatformNoticeData noticeData;
    @BindView(R.id.emptyView)
    QMUIEmptyView mEmptyView;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.tv_content)
    TextView mTvContent;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        //如找不到该类,请编译一下项目
        DaggerNoticeDetailComponent
                .builder()
                .appComponent(appComponent)
                .noticeDetailModule(new NoticeDetailModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
        return R.layout.activity_notice_detail;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mPresenter.getMsgContent(noticeData.getInboxId());
    }

    @Override
    public void showLoading() {
        mEmptyView.show(true);
    }

    @Override
    public void hideLoading() {
        mEmptyView.hide();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        RxUtil.showTipDialog(getActivity(), QMUITipDialog.Builder.ICON_TYPE_NOTHING, message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public void loadFail() {
        if (ObjectUtils.isNotEmpty(mEmptyView)) {
            mEmptyView.show(
                    false,
                    getResources().getString(R.string.public_emptyView_mode_desc_fail_title),
                    null,
                    getResources().getString(R.string.public_emptyView_mode_desc_retry),
                    v -> {
                        mPresenter.getMsgContent(noticeData.getInboxId());
                    });

        }
    }

    @Override
    public void update(NoticeDetailData data) {
        mTvContent.setText(data.getContent());
        mTvTitle.setText(data.getTitle());
    }

}
